(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

f(true, x, y) → f(and(gt(x, y), gt(y, s(s(0)))), plus(s(0), x), double(y))
gt(0, v) → false
gt(s(u), 0) → true
gt(s(u), s(v)) → gt(u, v)
and(x, true) → x
and(x, false) → false
plus(n, 0) → n
plus(n, s(m)) → s(plus(n, m))
double(0) → 0
double(s(x)) → s(s(double(x)))

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

f(true, x, y) → f(and(gt(x, y), gt(y, s(s(0)))), plus(s(0), x), double(y)) [1]
gt(0, v) → false [1]
gt(s(u), 0) → true [1]
gt(s(u), s(v)) → gt(u, v) [1]
and(x, true) → x [1]
and(x, false) → false [1]
plus(n, 0) → n [1]
plus(n, s(m)) → s(plus(n, m)) [1]
double(0) → 0 [1]
double(s(x)) → s(s(double(x))) [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

f(true, x, y) → f(and(gt(x, y), gt(y, s(s(0)))), plus(s(0), x), double(y)) [1]
gt(0, v) → false [1]
gt(s(u), 0) → true [1]
gt(s(u), s(v)) → gt(u, v) [1]
and(x, true) → x [1]
and(x, false) → false [1]
plus(n, 0) → n [1]
plus(n, s(m)) → s(plus(n, m)) [1]
double(0) → 0 [1]
double(s(x)) → s(s(double(x))) [1]

The TRS has the following type information:
f :: true:false → 0:s → 0:s → f
true :: true:false
and :: true:false → true:false → true:false
gt :: 0:s → 0:s → true:false
s :: 0:s → 0:s
0 :: 0:s
plus :: 0:s → 0:s → 0:s
double :: 0:s → 0:s
false :: true:false

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:

f(v0, v1, v2) → null_f [0]

And the following fresh constants:

null_f

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

f(true, x, y) → f(and(gt(x, y), gt(y, s(s(0)))), plus(s(0), x), double(y)) [1]
gt(0, v) → false [1]
gt(s(u), 0) → true [1]
gt(s(u), s(v)) → gt(u, v) [1]
and(x, true) → x [1]
and(x, false) → false [1]
plus(n, 0) → n [1]
plus(n, s(m)) → s(plus(n, m)) [1]
double(0) → 0 [1]
double(s(x)) → s(s(double(x))) [1]
f(v0, v1, v2) → null_f [0]

The TRS has the following type information:
f :: true:false → 0:s → 0:s → null_f
true :: true:false
and :: true:false → true:false → true:false
gt :: 0:s → 0:s → true:false
s :: 0:s → 0:s
0 :: 0:s
plus :: 0:s → 0:s → 0:s
double :: 0:s → 0:s
false :: true:false
null_f :: null_f

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

true => 1
0 => 0
false => 0
null_f => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

and(z, z') -{ 1 }→ x :|: x >= 0, z' = 1, z = x
and(z, z') -{ 1 }→ 0 :|: x >= 0, z = x, z' = 0
double(z) -{ 1 }→ 0 :|: z = 0
double(z) -{ 1 }→ 1 + (1 + double(x)) :|: x >= 0, z = 1 + x
f(z, z', z'') -{ 1 }→ f(and(gt(x, y), gt(y, 1 + (1 + 0))), plus(1 + 0, x), double(y)) :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
f(z, z', z'') -{ 0 }→ 0 :|: v0 >= 0, z'' = v2, v1 >= 0, z = v0, z' = v1, v2 >= 0
gt(z, z') -{ 1 }→ gt(u, v) :|: v >= 0, z' = 1 + v, z = 1 + u, u >= 0
gt(z, z') -{ 1 }→ 1 :|: z = 1 + u, z' = 0, u >= 0
gt(z, z') -{ 1 }→ 0 :|: v >= 0, z' = v, z = 0
plus(z, z') -{ 1 }→ n :|: n >= 0, z = n, z' = 0
plus(z, z') -{ 1 }→ 1 + plus(n, m) :|: n >= 0, z = n, z' = 1 + m, m >= 0

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V2),0,[f(V, V1, V2, Out)],[V >= 0,V1 >= 0,V2 >= 0]).
eq(start(V, V1, V2),0,[gt(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V2),0,[and(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V2),0,[plus(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V2),0,[double(V, Out)],[V >= 0]).
eq(f(V, V1, V2, Out),1,[gt(V3, V4, Ret00),gt(V4, 1 + (1 + 0), Ret01),and(Ret00, Ret01, Ret0),plus(1 + 0, V3, Ret1),double(V4, Ret2),f(Ret0, Ret1, Ret2, Ret)],[Out = Ret,V1 = V3,V2 = V4,V = 1,V3 >= 0,V4 >= 0]).
eq(gt(V, V1, Out),1,[],[Out = 0,V5 >= 0,V1 = V5,V = 0]).
eq(gt(V, V1, Out),1,[],[Out = 1,V = 1 + V6,V1 = 0,V6 >= 0]).
eq(gt(V, V1, Out),1,[gt(V7, V8, Ret3)],[Out = Ret3,V8 >= 0,V1 = 1 + V8,V = 1 + V7,V7 >= 0]).
eq(and(V, V1, Out),1,[],[Out = V9,V9 >= 0,V1 = 1,V = V9]).
eq(and(V, V1, Out),1,[],[Out = 0,V10 >= 0,V = V10,V1 = 0]).
eq(plus(V, V1, Out),1,[],[Out = V11,V11 >= 0,V = V11,V1 = 0]).
eq(plus(V, V1, Out),1,[plus(V12, V13, Ret11)],[Out = 1 + Ret11,V12 >= 0,V = V12,V1 = 1 + V13,V13 >= 0]).
eq(double(V, Out),1,[],[Out = 0,V = 0]).
eq(double(V, Out),1,[double(V14, Ret111)],[Out = 2 + Ret111,V14 >= 0,V = 1 + V14]).
eq(f(V, V1, V2, Out),0,[],[Out = 0,V15 >= 0,V2 = V16,V17 >= 0,V = V15,V1 = V17,V16 >= 0]).
input_output_vars(f(V,V1,V2,Out),[V,V1,V2],[Out]).
input_output_vars(gt(V,V1,Out),[V,V1],[Out]).
input_output_vars(and(V,V1,Out),[V,V1],[Out]).
input_output_vars(plus(V,V1,Out),[V,V1],[Out]).
input_output_vars(double(V,Out),[V],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. non_recursive : [and/3]
1. recursive : [double/2]
2. recursive : [gt/3]
3. recursive : [plus/3]
4. recursive : [f/4]
5. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into and/3
1. SCC is partially evaluated into double/2
2. SCC is partially evaluated into gt/3
3. SCC is partially evaluated into plus/3
4. SCC is partially evaluated into f/4
5. SCC is partially evaluated into start/3

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations and/3
* CE 12 is refined into CE [18]
* CE 13 is refined into CE [19]


### Cost equations --> "Loop" of and/3
* CEs [18] --> Loop 13
* CEs [19] --> Loop 14

### Ranking functions of CR and(V,V1,Out)

#### Partial ranking functions of CR and(V,V1,Out)


### Specialization of cost equations double/2
* CE 17 is refined into CE [20]
* CE 16 is refined into CE [21]


### Cost equations --> "Loop" of double/2
* CEs [21] --> Loop 15
* CEs [20] --> Loop 16

### Ranking functions of CR double(V,Out)
* RF of phase [16]: [V]

#### Partial ranking functions of CR double(V,Out)
* Partial RF of phase [16]:
- RF of loop [16:1]:
V


### Specialization of cost equations gt/3
* CE 11 is refined into CE [22]
* CE 10 is refined into CE [23]
* CE 9 is refined into CE [24]


### Cost equations --> "Loop" of gt/3
* CEs [23] --> Loop 17
* CEs [24] --> Loop 18
* CEs [22] --> Loop 19

### Ranking functions of CR gt(V,V1,Out)
* RF of phase [19]: [V,V1]

#### Partial ranking functions of CR gt(V,V1,Out)
* Partial RF of phase [19]:
- RF of loop [19:1]:
V
V1


### Specialization of cost equations plus/3
* CE 15 is refined into CE [25]
* CE 14 is refined into CE [26]


### Cost equations --> "Loop" of plus/3
* CEs [26] --> Loop 20
* CEs [25] --> Loop 21

### Ranking functions of CR plus(V,V1,Out)
* RF of phase [21]: [V1]

#### Partial ranking functions of CR plus(V,V1,Out)
* Partial RF of phase [21]:
- RF of loop [21:1]:
V1


### Specialization of cost equations f/4
* CE 8 is refined into CE [27]
* CE 7 is refined into CE [28,29,30,31,32,33,34,35]


### Cost equations --> "Loop" of f/4
* CEs [35] --> Loop 22
* CEs [33] --> Loop 23
* CEs [34] --> Loop 24
* CEs [32] --> Loop 25
* CEs [31] --> Loop 26
* CEs [30] --> Loop 27
* CEs [29] --> Loop 28
* CEs [28] --> Loop 29
* CEs [27] --> Loop 30

### Ranking functions of CR f(V,V1,V2,Out)
* RF of phase [22]: [V1/2-V2/2]

#### Partial ranking functions of CR f(V,V1,V2,Out)
* Partial RF of phase [22]:
- RF of loop [22:1]:
V1/2-V2/2


### Specialization of cost equations start/3
* CE 2 is refined into CE [36,37,38,39,40,41,42,43]
* CE 3 is refined into CE [44,45,46,47]
* CE 4 is refined into CE [48,49]
* CE 5 is refined into CE [50,51]
* CE 6 is refined into CE [52,53]


### Cost equations --> "Loop" of start/3
* CEs [49] --> Loop 31
* CEs [43] --> Loop 32
* CEs [42] --> Loop 33
* CEs [41] --> Loop 34
* CEs [40,53] --> Loop 35
* CEs [39,46,47,51] --> Loop 36
* CEs [36,38] --> Loop 37
* CEs [37,45,48,50] --> Loop 38
* CEs [44,52] --> Loop 39

### Ranking functions of CR start(V,V1,V2)

#### Partial ranking functions of CR start(V,V1,V2)


Computing Bounds
=====================================

#### Cost of chains of and(V,V1,Out):
* Chain [14]: 1
with precondition: [V1=0,Out=0,V>=0]

* Chain [13]: 1
with precondition: [V1=1,V=Out,V>=0]


#### Cost of chains of double(V,Out):
* Chain [[16],15]: 1*it(16)+1
Such that:it(16) =< Out/2

with precondition: [2*V=Out,V>=1]

* Chain [15]: 1
with precondition: [V=0,Out=0]


#### Cost of chains of gt(V,V1,Out):
* Chain [[19],18]: 1*it(19)+1
Such that:it(19) =< V

with precondition: [Out=0,V>=1,V1>=V]

* Chain [[19],17]: 1*it(19)+1
Such that:it(19) =< V1

with precondition: [Out=1,V1>=1,V>=V1+1]

* Chain [18]: 1
with precondition: [V=0,Out=0,V1>=0]

* Chain [17]: 1
with precondition: [V1=0,Out=1,V>=1]


#### Cost of chains of plus(V,V1,Out):
* Chain [[21],20]: 1*it(21)+1
Such that:it(21) =< V1

with precondition: [V+V1=Out,V>=0,V1>=1]

* Chain [20]: 1
with precondition: [V1=0,V=Out,V>=0]


#### Cost of chains of f(V,V1,V2,Out):
* Chain [[22],30]: 6*it(22)+2*s(9)+1*s(10)+1*s(11)+0
Such that:aux(6) =< 2*V1-3/2*V2
aux(4) =< 3*V1-2*V2
s(12) =< 6*V1-4*V2
aux(5) =< V1/2-V2/2
s(12) =< aux(4)
aux(2) =< aux(5)
it(22) =< aux(5)
aux(2) =< aux(6)
it(22) =< aux(6)
s(11) =< it(22)*aux(4)
s(10) =< aux(2)*2
s(9) =< s(12)

with precondition: [V=1,Out=0,V2>=3,V1>=V2+1]

* Chain [[22],23,30]: 6*it(22)+2*s(9)+1*s(10)+1*s(11)+2*s(13)+1*s(14)+1*s(16)+6
Such that:s(14) =< 2
aux(6) =< 2*V1-3/2*V2
aux(5) =< V1/2-V2/2
aux(8) =< 3*V1-2*V2
aux(9) =< 6*V1-4*V2
s(12) =< aux(9)
s(16) =< aux(9)
s(13) =< aux(8)
s(12) =< aux(8)
aux(2) =< aux(5)
it(22) =< aux(5)
aux(2) =< aux(6)
it(22) =< aux(6)
s(11) =< it(22)*aux(8)
s(10) =< aux(2)*2
s(9) =< s(12)

with precondition: [V=1,Out=0,V2>=3,V1>=V2+1]

* Chain [30]: 0
with precondition: [Out=0,V>=0,V1>=0,V2>=0]

* Chain [29,30]: 6
with precondition: [V=1,V1=0,V2=0,Out=0]

* Chain [28,30]: 2*s(17)+6
Such that:aux(10) =< V2
s(17) =< aux(10)

with precondition: [V=1,V1=0,Out=0,2>=V2,V2>=1]

* Chain [27,30]: 1*s(19)+1*s(20)+6
Such that:s(19) =< 2
s(20) =< V2

with precondition: [V=1,V1=0,Out=0,V2>=3]

* Chain [26,30]: 1*s(21)+6
Such that:s(21) =< V1

with precondition: [V=1,V2=0,Out=0,V1>=1]

* Chain [25,30]: 2*s(22)+2*s(23)+6
Such that:aux(11) =< V1
aux(12) =< V2
s(22) =< aux(11)
s(23) =< aux(12)

with precondition: [V=1,Out=0,2>=V2,V1>=1,V2>=V1]

* Chain [24,30]: 3*s(26)+1*s(28)+6
Such that:s(28) =< V1+1
aux(13) =< V2
s(26) =< aux(13)

with precondition: [V=1,Out=0,2>=V2,V2>=1,V1>=V2+1]

* Chain [23,30]: 2*s(13)+1*s(14)+1*s(16)+6
Such that:s(14) =< 2
aux(7) =< V1
s(16) =< V2
s(13) =< aux(7)

with precondition: [V=1,Out=0,V1>=1,V2>=3,V2>=V1]


#### Cost of chains of start(V,V1,V2):
* Chain [39]: 1
with precondition: [V=0]

* Chain [38]: 2*s(53)+6
Such that:s(52) =< V2
s(53) =< s(52)

with precondition: [V1=0,V>=0]

* Chain [37]: 1*s(54)+1*s(55)+6
Such that:s(54) =< 2
s(55) =< V2

with precondition: [V>=0,V1>=0,V2>=0]

* Chain [36]: 3*s(56)+1*s(57)+6
Such that:s(57) =< V
aux(18) =< V1
s(56) =< aux(18)

with precondition: [V>=0,V1>=1]

* Chain [35]: 2*s(62)+2*s(63)+1*s(64)+6
Such that:s(64) =< V
s(60) =< V1
s(61) =< V2
s(62) =< s(60)
s(63) =< s(61)

with precondition: [V>=1]

* Chain [34]: 1*s(65)+3*s(67)+6
Such that:s(65) =< V1+1
s(66) =< V2
s(67) =< s(66)

with precondition: [V=1,2>=V2,V2>=1,V1>=V2+1]

* Chain [33]: 1*s(68)+1*s(70)+2*s(71)+6
Such that:s(68) =< 2
s(69) =< V1
s(70) =< V2
s(71) =< s(69)

with precondition: [V=1,V1>=1,V2>=3,V2>=V1]

* Chain [32]: 1*s(72)+1*s(78)+2*s(79)+12*s(81)+2*s(82)+2*s(83)+4*s(84)+6
Such that:s(72) =< 2
s(73) =< 2*V1-3/2*V2
s(74) =< 3*V1-2*V2
s(75) =< 6*V1-4*V2
s(76) =< V1/2-V2/2
s(77) =< s(75)
s(78) =< s(75)
s(79) =< s(74)
s(77) =< s(74)
s(80) =< s(76)
s(81) =< s(76)
s(80) =< s(73)
s(81) =< s(73)
s(82) =< s(81)*s(74)
s(83) =< s(80)*2
s(84) =< s(77)

with precondition: [V=1,V2>=3,V1>=V2+1]

* Chain [31]: 1
with precondition: [V1=1,V>=0]


Closed-form bounds of start(V,V1,V2):
-------------------------------------
* Chain [39] with precondition: [V=0]
- Upper bound: 1
- Complexity: constant
* Chain [38] with precondition: [V1=0,V>=0]
- Upper bound: nat(V2)*2+6
- Complexity: n
* Chain [37] with precondition: [V>=0,V1>=0,V2>=0]
- Upper bound: V2+8
- Complexity: n
* Chain [36] with precondition: [V>=0,V1>=1]
- Upper bound: V+3*V1+6
- Complexity: n
* Chain [35] with precondition: [V>=1]
- Upper bound: V+6+nat(V1)*2+nat(V2)*2
- Complexity: n
* Chain [34] with precondition: [V=1,2>=V2,V2>=1,V1>=V2+1]
- Upper bound: V1+3*V2+7
- Complexity: n
* Chain [33] with precondition: [V=1,V1>=1,V2>=3,V2>=V1]
- Upper bound: 2*V1+V2+8
- Complexity: n
* Chain [32] with precondition: [V=1,V2>=3,V1>=V2+1]
- Upper bound: 8*V1-8*V2+ (30*V1-20*V2+ (6*V1-4*V2+8+ (V1/2-V2/2)* (6*V1-4*V2)))
- Complexity: n^2
* Chain [31] with precondition: [V1=1,V>=0]
- Upper bound: 1
- Complexity: constant

### Maximum cost of start(V,V1,V2): max([max([V+5+nat(V1)*3,nat(3*V1-2*V2)*2+7+nat(3*V1-2*V2)*2*nat(V1/2-V2/2)+nat(6*V1-4*V2)*5+nat(V1/2-V2/2)*16]),nat(V2)+5+max([nat(V2)+max([nat(V1+1)+nat(V2),nat(V1)*2+V]),nat(V1)*2+2])])+1
Asymptotic class: n^2
* Total analysis performed in 478 ms.

(10) BOUNDS(1, n^2)